﻿namespace TxtManager.Core.Entities;

public abstract  class BaseEntity<TId>
{
    /// <summary>
    /// 实体Id
    /// </summary>
    public TId Id { get; protected set; } // 保护set防止外部修改


    public DateTime CreateTime { get; private set; } = DateTime.Now;

    public bool IsDeleted { get; private set; }
    public DateTime? DeleteTime { get; private set; }

    public void SoftDelete()
    {
        IsDeleted = true;

        DeleteTime = DateTime.Now;
    }



    // 重写Equals和GetHashCode
    public override bool Equals(object? obj)
    {
        if (obj is not BaseEntity<TId> other)
            return false;

        if (ReferenceEquals(this, other))
            return true;

        if (GetType() != other.GetType())
            return false;

        return Id.Equals(other.Id);
    }

    public override int GetHashCode() =>
        (GetType().ToString() + Id).GetHashCode();
}